package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo5 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();)
        {
            Statement statement = connection.createStatement();//创建Statement对象,用于执行SQL语句
            String sql="select *from teacher ";
            ResultSet rs = statement.executeQuery(sql);//返回结果集
            while(rs.next()){
                int id=rs.getInt("id");
                String name=rs.getString("name");
                int salary=rs.getInt("salary");
                String title=rs.getString("title");
                System.out.println("{"+id+","+name+","+salary+","+title+"}");
            }
        } catch (Exception e) {
           e.printStackTrace();
        }
    }
}
